package com.bicntech.admin.controller.system;

import cn.hutool.core.util.ObjectUtil;
import com.bicntech.common.core.domain.R;
import com.bicntech.common.core.domain.entity.SysDictData;
import com.bicntech.system.service.ISysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/system/dict/data")
@RequiredArgsConstructor
@RestController
public class SysDictDataController {

    private final ISysDictTypeService dictTypeService;

    @GetMapping(value = "/type/{dictType}")
    public R<List<SysDictData>> dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (ObjectUtil.isNull(data)) {
            data = new ArrayList<>();
        }
        return R.ok(data);
    }

}
